/**
 *  WebSocket
 */

var socket = null;

var url = "";

function ServerConn() {
    console.log("websocket");
    socket = new WebSocket(url);
    socket.onopen = WSonOpen;
    socket.onmessage = WSonMessage;
    socket.onclose = WSonClose;
    socket.onerror = WSonError;

}

function WSonError() {
    console.log("ws err")
}

function WSonOpen() {
    console.log("ws conn to " + url);
    PGsetStateConn("online");
}

function WSonClose(e) {
    socket = null;
    PGsetStateConn("offline");
    console.log("ws closed (" + e.code + ")");
}

function WSonMessage(e) {
    console.log("ws msg: " + e.data);
    parsMessage(e.data)
}

function WSsetURL(l) {
    url = l;
}


function WSSendMessage(msg) {
    console.log("msg: ", msg);
    if (socket != null) {
        socket.send(msg)
    } else {
        PGshowNotify("网络服务已经断开", "error");
    }
}






